#include "include/customshortcut_qmeta.h"


namespace
{

	const QString defaultShortcut = "defaultShortcut";
	const QString currentShortcut = "currentShortcut";

	QVariant toQVariant(const QKeySequence& sequence)
	{
		QVariant v;
		v.setValue(sequence);
		return v;
	}

	QKeySequence extractSequence(const QMap<QString, QVariant>& map, const QString& shorcutName)
	{
		if (!map.contains(shorcutName))
			return QKeySequence();

		QVariant v = map[shorcutName];
		return v.value<QKeySequence>();
	}

} //private namespace


void ShortcutsMetaHelper::setDefaultShortcut(QMap<QString, QVariant> &map, const QKeySequence& sequence)
{
	map[defaultShortcut] = toQVariant(sequence);
}

void ShortcutsMetaHelper::setCurrentShortcut(QMap<QString, QVariant> &map, const QKeySequence& sequence)
{
	map[currentShortcut] = toQVariant(sequence);
}

QKeySequence ShortcutsMetaHelper::getDefaultShortcut(const QMap<QString, QVariant> &map)
{
	return extractSequence(map, defaultShortcut);
}

QKeySequence ShortcutsMetaHelper::getCurrentShortcut(const QMap<QString, QVariant> &map)
{
	return extractSequence(map, currentShortcut);
}
